/**
* @file 签到
* @author 张超
* @created 2023/7/05 08:00
* @updated 2023/7/05 18:00
*/
<template>
	<view class="sign">
		<view class="sign-titleBg" :style="{ background:'url('+fdw2+')',backgroundSize:'100% 100% !important'}">
			<view class="title" @click="fanh">
				<u-icon name="arrow-left" size="40" color="#fff"></u-icon>
				<text>签到中心</text>
			</view>
			<view class="">我的消费积分</view>
			<view class="">{{signCheckData.score?signCheckData.score:''}}</view>
			<view class="btn" @click="goDuih">兑换</view>
		</view>
		<!-- 签到天数 -->
		<view class="sign-qiand">
			<view class="siginin-day">
				<view class="day-title">连续签到领好礼</view>
				<view class="day-content">
					<view :class="firstTime>=1||firstTime==7?'itemAc':'item'" @click="signln">
						<text>第1天</text>
						<image src="@/static/shop/jifen.png" mode=""></image>
						<text>{{signCheckData.one?signCheckData.one:''}}积分</text>
					</view>
					<view :class="firstTime>=2||firstTime==7?'itemAc':'item'" @click="signln">
						<text>第2天</text>
						<image src="@/static/shop/jifen.png" mode=""></image>
						<text>{{signCheckData.two?signCheckData.two:''}}积分</text>
					</view>
					<view :class="firstTime>=3||firstTime==7?'itemAc':'item'" @click="signln">
						<text>第3天</text>
						<image src="@/static/shop/jifen.png" mode=""></image>
						<text>{{signCheckData.three?signCheckData.three:''}}积分</text>
					</view>
					<view :class="firstTime>=4||firstTime==7?'itemAc':'item'" @click="signln">
						<text>第4天</text>
						<image src="@/static/shop/jifen.png" mode=""></image>
						<text>{{signCheckData.four?signCheckData.four:''}}积分</text>
					</view>
					<view :class="firstTime>=5||firstTime==7?'itemAc':'item'" @click="signln">
						<text>第5天</text>
						<image src="@/static/shop/jifen.png" mode=""></image>
						<text>{{signCheckData.five?signCheckData.five:''}}积分</text>
					</view>
					<view :class="firstTime>=6||firstTime==7?'itemAc':'item'" @click="signln">
						<text>第6天</text>
						<image src="@/static/shop/jifen.png" mode=""></image>
						<text>{{signCheckData.six?signCheckData.six:''}}积分</text>
					</view>
					<view :class="firstTime==7?'item-sevenAc':'item-seven'" @click="signln">
						<view>
							<text>第7天</text>
							<text>神秘大礼包</text>
						</view>
						<image src="@/static/shop/libao.png" style="width: 104rpx;height: 119rpx;" mode=""></image>
					</view>
				</view>
			</view>
		</view>
		<!-- 做任务赚积分 -->
		<view class="zhuanjf">
			<view class="zhuanjf-title">做任务赚积分</view>
			<view class="zhuanjf-text" v-if="taskList.length>0">
				<image :src="taskList[0].image"></image>
				<view class="">
					<text>{{taskList[0].title}}</text>
					<text>{{taskList[0].desc}}</text>
				</view>
				<view class="btn" v-if="taskList[0].usertasklognum==0" @click="goWanc(taskList[0],0)">
					去完成
				</view>
				<view class="btn" v-else>
					已完成
				</view>
			</view>
			<view class="zhuanjf-text" v-if="taskList.length>1&&applyStatus==0">
				<image :src="taskList[1].image"></image>
				<view class="">
					<text>{{taskList[1].title}}</text>
					<text>{{taskList[1].desc}}</text>
				</view>
				<view class="btn" v-if="taskList[1].usertasklognum==0" @click="goWanc(taskList[1],1)">
					去完成
				</view>
				<view class="btn" v-else>
					已完成
				</view>
			</view>
		</view>
		<u-popup v-model="show" mode="center" border-radius="20" :mask-close-able="false">
			<view class="pop">
				<!-- <view class="pop-title">
					<view>
						<text>{{video.title}}</text>
						<u-icon name="close"></u-icon>
					</view>
					<view>倒计时：{{time}}</view>
				</view> -->
				<view class="pop-video">
					<video :show-progress="false" :enable-progress-gesture="false" :src="video122" @ended="taskscoreRe"
						autoplay="true" object-fit="fill" show-play-btn="false"></video>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		signCheck,
		signup,
		taskscore,
		config
	} from '@/network/api.js'
	import {
		getUserinfo
	} from '@/network/loginAndMy.js'
	export default {
		data() {
			return {
				// 签到页面数据
				signCheckData: {},
				// 判断是否可以签到
				signCheckCode: 0,
				// 点击立即签到使其加一
				firstTime: 0,
				// 做任务赚积分
				taskList: [],
				// 视频弹框数据
				video: [],
				// 弹框
				show: false,
				// 倒计时
				time: 30,
				user_info: {},
				// 看视频次数
				number: 0,
				// 当前播放视频
				video122: "",
				fdw2: '../../../static/shop/qiand.png',
				// 等于1隐藏  0开启
				applyStatus: "",
				// 请求状态识别变量
				requestStatus: false
			}
		},
		onShow() {
			this.configRe()
		},
		methods: {
			// 获取配置信息
			configRe() {
				config().then(res => {
					this.applyStatus = res.data.applyStatus
					this.getUserinfoRe()
					this.signCheckRe()
				})
			},
			// 点击签到弹框触发事件
			signln() {
				if (this.requestStatus) {
					// 利用 return 终止函数继续运行
					return false;
				}
				console.log('按钮点击函数执行');
				// 执行函数
				this.requestStatus = true;
				if (this.signCheckCode == 1) {
					signup().then(res => {
						if (res.code == 1) {
							setTimeout(() => {
								this.signCheckRe()
							}, 200)
							setTimeout(() => {
								this.signCheckRe()
							}, 300)
							setTimeout(() => {
								this.signCheckRe()
							}, 400)
						}
					})
				} else {
					uni.showToast({
						title: "今日打卡已完成",
						icon: "none",
						duration: 2000,
					});
				}
				setTimeout(() => {
					// 改变 requestStatus
					this.requestStatus = false;
				}, 1000);
			},
			// 获取用户信息
			getUserinfoRe() {
				getUserinfo().then(res => {
					if (res.code == 1) {
						this.user_info = res.data
						// console.log(this.user_info.ispass,'入金')
					}
				})
			},
			signCheckRe() {
				signCheck().then(res => {
					console.log(res, '签到')
					this.signCheckData = res.data
					this.taskList = res.data.task_list
					this.signCheckCode = res.code
					let that = this
					if (res.code == 0) {//已签到
						if (that.signCheckData.signing > 7) {
							//当连续签到时间大于7时，采取余额取值
							if (that.signCheckData.signing % 7 != 0) {
								that.setData({
									firstTime: that.signCheckData.signing % 7
								})
							} else {
								//当整除时，考虑到已签到，用户已签满N个七天，直接赋值
								that.setData({
									firstTime: 7
								})
							}
						} else {
							//当小于七天时，直接赋值
							that.setData({
								firstTime: that.signCheckData.signing
							})
						}
					} else {//未签到
						//连续签到状态
						if (that.signCheckData.signing == 0) {
							that.setData({
								firstTime: that.signCheckData.signing
							})
						} else {
							// 非连续签到状态
							if (that.signCheckData.signing % 7 != 0) {
								// 已签到多少天
								that.setData({
									firstTime: that.signCheckData.signing % 7
								})
							} else {
								// 签到过，本周期未签到过
								that.setData({
									firstTime: 0
								})
							}
						}
					}
				})
			},
			// 做任务
			goWanc(item, index) {
				if (index == 0) {
					// uni.navigateTo({
					// 	url: '/pages/subpackage/my/promotionQRCode'
					// })
					uni.showModal({
						content: this.user_info.ownid, //模板中提示的内容
						confirmText: '复制',
						success: (res) => { //点击复制内容的后调函数
							if (res.confirm) {
								//uni.setClipboardData方法就是讲内容复制到粘贴板
								//意思是H5端没有这个接口！！！
								uni.setClipboardData({
									data: this.user_info.ownid, //要被复制的内容
									success: function() {
										//重点~做笔记
										//在success中加入uni.hideToast()可以解决
										uni.showToast({
											title: "复制成功",
											icon: "none",
											duration: 2000,
										});
										//以下就可自定义操作了~
									},
									fail: function(err) {
										uni.showToast({
											title: "复制失败",
											icon: "none",
											duration: 2000,
										});
									}
								});
							} else if (res.cancel) {
								uni.showToast({
									title: "取消复制",
									icon: "none",
									duration: 2000,
								});
							}
						}
					});
				} else {
					this.video = item.videourl
					this.video122 = this.video[0]
					this.time = 30
					this.show = true
				}
			},
			// 视频倒计时
			// countDown(type) {
			// 	let that = this
			// 	let intervalId;
			// 	if (type == 'close') {
			// 		console.log('停止倒计时')
			// 		clearInterval(intervalId); // 停止重复执行
			// 	} else {
			// 		intervalId = setInterval(function() {
			// 			that.time--;
			// 			if (that.time <= 0) {
			// 				clearInterval(intervalId); // 停止重复执行
			// 				that.taskscoreRe()
			// 			}
			// 		}, 1000);
			// 	}
			// },
			// 看视频领取积分,必须看完多个视频
			taskscoreRe() {
				if ((this.number + 1) == this.video.length) {
					this.fsad()
				} else {
					this.number++
					this.video122 = this.video[this.number]
				}
			},
			// 请求完成接口
			fsad() {
				let data = {
					flag: 'lookVideo'
				}
				taskscore(data).then(res => {
					if (res.code == 1) {
						this.signCheckRe()
						uni.showToast({
							title: "已完成,即将关闭",
							icon: "none",
							duration: 2000,
						});
						setTimeout(() => {
							this.show = false
						}, 1000)
					}
				})
			},
			// 返回上一级
			fanh() {
				// uni.navigateBack({
				// 	delta: 1
				// })
				uni.reLaunch({
					url: '/pages/main/index/index'
				})
			},
			// 跳转到兑换页
			goDuih() {
				let data = {
					type: 'pay',
					typee: 2
				}
				uni.navigateTo({
					url: '/pages/subpackage/my/convert?data=' + JSON.stringify(data)
				})
			}
		}
	}
</script>

<style lang="scss">
	.sign {
		height: 100vh;
		background-color: #F3F3F3;

		.sign-titleBg {
			padding: 90rpx 30rpx 60rpx 30rpx;
			height: 560rpx;

			.title {
				display: flex;
				align-items: center;

				>text {
					display: block;
					margin: 0 auto;
					font-size: 36rpx;
					color: #fff;
					font-family: PingFang SC, PingFang SC-Bold;
				}
			}

			>view:nth-child(2) {
				margin-top: 60rpx;
				font-size: 30rpx;
				color: #fff;
				font-family: PingFang SC, PingFang SC-Medium;
			}

			>view:nth-child(3) {
				margin-top: 10rpx;
				font-size: 60rpx;
				color: #fff;
				font-family: PingFang SC, PingFang SC-Bold;
			}

			.btn {
				width: 110rpx;
				height: 50rpx;
				opacity: 0.74;
				margin-top: 10rpx;
				text-align: center;
				line-height: 50rpx;
				font-size: 30rpx;
				color: #3a4059;
				background: #f9f9f9;
				border-radius: 25rpx;
				font-family: PingFang SC, PingFang SC-Bold;
			}

			.btn:active {
				background-color: #f1a04f;
			}
		}

		// 签到天数
		.sign-qiand {
			height: 500rpx;
			margin: 0 30rpx;
			margin-top: -130rpx;
			border-radius: 30rpx;
			background-color: #fff;

			.siginin-day {
				padding: 30rpx;

				.day-title {
					font-size: 30rpx;
					font-family: PingFang SC, PingFang SC-Bold;
				}

				.day-content {
					display: flex;
					justify-content: space-between;
					flex-wrap: wrap;
					margin-top: 40rpx;

					.item {
						display: flex;
						flex-direction: column;
						align-items: center;
						width: 144rpx;
						height: 172rpx;
						padding-top: 20rpx;
						margin-bottom: 20rpx;
						background: #f4f4f4;
						box-sizing: border-box;
						border-radius: 11rpx;

						>text:nth-child(1) {
							font-size: 30rpx;
							color: #1C1C1E;
						}

						>image:nth-child(2) {
							width: 53rpx;
							height: 53rpx;
							margin: 12rpx 0;
						}

						>text:nth-child(3) {
							font-size: 22rpx;
							color: #99999b;
						}
					}

					.itemAc {
						display: flex;
						flex-direction: column;
						align-items: center;
						width: 144rpx;
						height: 172rpx;
						padding-top: 20rpx;
						margin-bottom: 20rpx;
						background: #FF9B3F;
						box-sizing: border-box;
						border-radius: 11rpx;

						>text:nth-child(1) {
							font-size: 30rpx;
							color: #FFFFFF;
						}

						>image:nth-child(2) {
							width: 53rpx;
							height: 53rpx;
							margin: 12rpx 0;
						}

						>text:nth-child(3) {
							font-size: 22rpx;
							color: #FFFFFF;
						}
					}

					.item-sevenAc {
						display: flex;
						width: 313rpx;
						height: 172rpx;
						padding: 20rpx 0 0 30rpx;
						background: #FF9B3F;
						border-radius: 11rpx;
						box-sizing: border-box;

						>view:nth-child(1) {
							display: flex;
							flex-direction: column;

							>text:nth-child(1) {
								margin-bottom: 15rpx;
								font-size: 30rpx;
								color: #1C1C1E;
							}

							>text:nth-child(2) {
								font-size: 26rpx;
								color: #99999B;
							}
						}

						>image:nth-child(2) {
							width: 104rpx;
							height: 119rpx;
							margin: 20rpx 0 0 20rpx;
						}
					}

					.item-seven {
						display: flex;
						width: 313rpx;
						height: 172rpx;
						background: #f4f4f4;
						padding: 20rpx 0 0 30rpx;
						border-radius: 11rpx;
						box-sizing: border-box;

						>view:nth-child(1) {
							display: flex;
							flex-direction: column;

							>text:nth-child(1) {
								margin-bottom: 15rpx;
								font-size: 30rpx;
								color: #1C1C1E;
							}

							>text:nth-child(2) {
								font-size: 26rpx;
								color: #99999B;
							}
						}

						>image:nth-child(2) {
							width: 104rpx;
							height: 119rpx;
							margin: 20rpx 0 0 20rpx;
						}
					}
				}

				.day-btm {
					width: 347rpx;
					height: 78rpx;
					line-height: 78rpx;
					text-align: center;
					margin: 20rpx auto;
					background: linear-gradient(-90deg, #f1a241 1%, #eb573b 100%);
					border-radius: 39rpx;
					box-shadow: 3.5rpx 6.06rpx 24rpx 7rpx rgba(235, 97, 59, 0.52);
					font-size: 36rpx;
					color: #FFFFFF;
				}

				.day-hint {
					display: flex;
					justify-content: center;
					align-items: center;

					>text {
						margin-right: 5rpx;
						font-size: 30rpx;
					}

					>image {
						width: 30rpx;
						height: 30rpx;
					}
				}
			}
		}

		.zhuanjf {
			margin: 30rpx;
			padding: 30rpx;
			border-radius: 30rpx;
			background-color: #fff;

			.zhuanjf-title {}

			.zhuanjf-text {
				display: flex;
				align-items: center;
				height: 120rpx;
				margin-top: 20rpx;
				padding: 24rpx 0;

				>image {
					width: 74rpx;
					height: 74rpx;
					margin-right: 20rpx;
					border-radius: 50%;
				}

				>view:nth-child(2) {
					>text:nth-child(1) {
						display: block;
						font-size: 28rpx;
						font-family: PingFang SC, PingFang SC-Bold;
					}

					>text:nth-child(2) {
						font-size: 24rpx;
						font-family: PingFang SC, PingFang SC-Medium;
						color: #999999;
					}
				}

				.btn {
					width: 110rpx;
					height: 56rpx;
					text-align: center;
					line-height: 56rpx;
					margin-left: auto;
					font-size: 24rpx;
					color: #B97E00;
					border: 1rpx solid #b97e00;
					border-radius: 15px;
				}

				.btn:active {
					color: #fff;
					background-color: #999999;
				}
			}
		}

		.pop {
			height: 100%;
			display: flex;
			flex-direction: column;

			.pop-title {
				text-align: center;
				height: 140rpx;
				margin: 20rpx 30rpx;

				>view:nth-child(1) {
					display: flex;
					justify-content: center;
					font-size: 30rpx;

					.u-icon {
						margin-left: auto;
					}
				}

				>view:nth-child(2) {
					margin-top: 10rpx;
					font-size: 20rpx;
					color: red
				}

				// border:10rpx solid red
			}

			.pop-video {
				margin-top: auto;
				line-height: 0;

				video {}
			}

		}
	}
</style>